
package org.jetnuke.repository;

import java.util.List;

import net.jforum.cache.CacheEngine;
import net.jforum.cache.Cacheable;

import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.dao.MessageDAO;

public class MessageRepository implements Cacheable{
	private static CacheEngine cache;
	private static final String FQN="jetnuke/messages";
	public void setCacheEngine(CacheEngine cacheEngine) {
		cache = cacheEngine;
		
	}
	public synchronized static List getActiveMessages()throws Exception{
		List l=(List)cache.get(FQN);
		if(l==null){
			l=loadActiveMessages();
		}
		return l;
	}
	private static List loadActiveMessages()throws Exception{
		MessageDAO mm=DataAccessDriver.getInst().newMessageDAO();
		List messageList = mm.selectActive();
		cache.add(FQN,messageList);
		return messageList;
	}
	public synchronized static void clearCache() {
		cache.remove(FQN);
	}

}
